package com.llh.demo4shiro.service;

import com.llh.demo4shiro.model.Authority;
import com.llh.demo4shiro.repository.AuthorityRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>CreatedAt: 2020/9/17 9:52</p>
 *
 * @author llh
 */
@Service
public class AuthorityService {
    @Autowired
    private AuthorityRepo authorityRepo;

    public Authority add(Authority authority) {
        return authorityRepo.save(authority);
    }

    public boolean existedAuthority(String authorityName) {
        Authority authority = new Authority();
        authority.setName(authorityName);
        Example<Authority> example = Example.of(authority);
        long count = authorityRepo.count(example);
        return count > 0;
    }

    public List<Authority> all(){
        return authorityRepo.findAll();
    }

}
